package cn.stylefeng.guns.modular.system.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.system.entity.DispatchOrderCheck;
import cn.stylefeng.guns.modular.system.mapper.DispatchOrderCheckMapper;
import cn.stylefeng.guns.modular.system.model.params.DispatchOrderCheckParam;
import cn.stylefeng.guns.modular.system.model.result.DispatchOrderCheckResult;
import  cn.stylefeng.guns.modular.system.service.DispatchOrderCheckService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 订货单审核表 服务实现类
 * </p>
 *
 * @author ZhangJun
 * @since 2019-07-04
 */
@Service
public class DispatchOrderCheckServiceImpl extends ServiceImpl<DispatchOrderCheckMapper, DispatchOrderCheck> implements DispatchOrderCheckService {

    @Override
    public void add(DispatchOrderCheckParam param){
        DispatchOrderCheck entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(DispatchOrderCheckParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(DispatchOrderCheckParam param){
        DispatchOrderCheck oldEntity = getOldEntity(param);
        DispatchOrderCheck newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public DispatchOrderCheckResult findBySpec(DispatchOrderCheckParam param){
        return null;
    }

    @Override
    public List<DispatchOrderCheckResult> findListBySpec(DispatchOrderCheckParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(DispatchOrderCheckParam param,Integer type){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext,param,type);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(DispatchOrderCheckParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private DispatchOrderCheck getOldEntity(DispatchOrderCheckParam param) {
        return this.getById(getKey(param));
    }

    private DispatchOrderCheck getEntity(DispatchOrderCheckParam param) {
        DispatchOrderCheck entity = new DispatchOrderCheck();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
